<template>
	<PageLayout title="新增项目">
		<EditLayout @confirm="handlerSave">
			<view class="input-form-box">
				<up-form
					labelWidth="100"
					labelAlign="right"
					labelPosition="left"
					:model="projectData"
					ref="form1"
				>       
					<up-form-item
							label="项目名称"
							prop="name"
							borderBottom
					>
						<up-input
								v-model="projectData.name"
								
								placeholder="请填写项目名称"
								border="none"
						></up-input>
					</up-form-item>
				</up-form>
			</view>
		</EditLayout>
	</PageLayout>
    
</template>

<script setup lang="ts">

    import {ref,getCurrentInstance} from 'vue'
	import PageLayout from '../../components/myLayout/PageLayout.vue';
	import EditLayout from '../../components/myLayout/EditLayout.vue';
	import { ProjectAddReq, ProjectGetReq } from '../../http/project';
	import { MyAlert } from '../../utils/utils';
import { useProjectStore } from '../../store/projectStore';

	const projectStore=useProjectStore()

	const instance = getCurrentInstance().proxy
    const eventChannel = instance.getOpenerEventChannel();

    const projectData=ref({
        name:"",
		remask:""
    })

    const rules=ref({})

	const handlerSave=()=>{
		ProjectAddReq({...projectData.value}).then(async (res)=>{
			const confirm=await MyAlert({title:"创建成功！",content:"是否跳转到项目中？"}).catch(()=>{
				uni.navigateBack()
			})
			if(confirm!==true){
				return
			}
			// const res_1=await ProjectGetReq({id:res.data.id})
			// await projectStore.setProject(res_1.data)
			uni.redirectTo({
				url:"/pages/aaProject/index?id="+res.data.id
			})
		})
	}

</script>

<style lang="scss" scoped>
	
</style>